--
-- Author: shunguo.chen
-- Date: 2018-04-03 17:01:01
--
-- CosKOFInfo kof 角色扮演信息

local UserBaseInfo = require("app.public.dao.UserBaseInfo")

local fileName = string.getModeName(...)
local ClassRef = class(fileName)

function ClassRef:ctor(data)
	self._poolIds = nil
	self._poolRoles = nil

	if data then
		self:init(data)
	end
end

-- message KOFRollPlayInfo{
-- 	int32 targetID = 1;
-- 	string teamID = 2;
-- 	int64 uid = 3;
-- 	base.UserBaseInfo userInfo = 4;
-- 	repeated int32 kofIDs = 5;
-- 	int32 leftSeconds = 6;
-- 	RollPlayChoiceStatus status = 7;
-- }
function ClassRef:init(data)
	self.targetID = data.targetID
	self.teamID = data.teamID
	self.leftSeconds = data.leftSeconds
	self.status = data.status

	self._initTime = app:getTime()

	self.baseInfo = UserBaseInfo.new(data.userInfo)

	local roles = {}
	for i,v in ipairs(data.kofIDs) do
		local role = app:sendMsg("CosplayModel", "getRoleById", v)
		roles[#roles + 1] = role
	end
	self._roles = roles
end

-- 剩余时间
function ClassRef:getRestTime()
	return self.leftSeconds - math.floor(app:getTime() - self._initTime)
end

function ClassRef:isMyTeam()
	return self.baseInfo.uid == UD:getUid()
end

function ClassRef:getRoles()
	return self._roles
end

function ClassRef:getRoleLen()
	return #self._roles
end

function ClassRef:isFinish()
	return self.status == "finished"
end

function ClassRef:setPoolRoles(ids)
	self._poolIds = ids
	self._poolRoles = nil
end

function ClassRef:getPoolRoles()
	if not self._poolRoles then
		local roles = {}
		for i,v in ipairs(self._poolIds) do
			local role = app:sendMsg("CosplayModel", "getRoleById", v)
			roles[#roles + 1] = role
		end
		self._poolRoles = roles
	end
	return self._poolRoles
end

return ClassRef